package myFram.util;
import java.util.*;
import java.sql.*;

import com.loginbean.DB;

public class Query {
	
	private HashMap<Integer,String>[] hp;
	private DB       db=null;
	private ResultSet rs=null;	
	
	public HashMap<Integer,String>[] getRoom(String sql)
	{
		try{
			hp=new HashMap[42];
			db=new DB();
			rs=db.executeQuery(sql);
			
			while(rs.next())
			{
				 int temp=rs.getInt("time");
				 int time=getNum(temp);
				 String str=rs.getString("courseName");
				 int scheduleId=rs.getInt("scheduleId");
				 hp[time]= new HashMap<Integer,String>();
				 hp[time].put(scheduleId,str);
				 
			}
			
			
		}catch(Exception e){
			e.printStackTrace();
			
		}
		finally{
			db.close();
		}
		
		return hp;
	}
	public HashMap<Integer,String>[] getTime(String sql) throws SQLException
	{
		try
		{
			hp=new HashMap[10];
			DB db= new DB();
			rs=db.executeQuery(sql);
			
			for(int i=0;i<10;i++)
			{
				hp[i]= new HashMap<Integer,String>();
			}
			while(rs.next())
			{
				int roomNo=rs.getInt("roomNo");
				String room=(new Integer(roomNo)).toString();
				
				String buildingNo=rs.getString("buildingNo");
				int building=getBuildingNo(buildingNo);
				
				int scheduleId=rs.getInt("scheduleId");
				hp[building-1].put(scheduleId, room);
				
			}
		}
		catch(Exception e)
		{
			e.printStackTrace();
		}
		if(rs.next())
			db.close();
		return hp;
	}
	public int getNum(int time)
	{
		int w=time/10;
		int t=time%10;
		return (t-1)*7+w-1;
	}
	public  int getBuildingNo(String no)
	{
		int building=0;
		if(("1").equals(no))
			building=1;
		if(("2").equals(no))
			building=2;
		if(("3").equals(no))
			building=3;
		if(("4").equals(no))
			building=4;
		if(("zhu").equals(no))
			building=5;
		if(("zhunan").equals(no))
			building=6;
		if(("zhubei").equals(no))
			building=7;
		if(("M").equals(no))
			building=8;
		if(("F").equals(no))
			building=9;
		if(("G").equals(no))
			building=10;
		return building;
	}
	

}
